//
//  GTVideoToolBar.m
//  SampleApp2
//
//  Created by GXHC on 2023/6/26.
//

#import "GTVideoToolBar.h"
#import <Masonry/Masonry.h>
@interface GTVideoToolBar ()
@property (nonatomic, strong, readwrite) UIImageView *avatorImageView;
@property (nonatomic, strong, readwrite) UILabel *nickLabel;

@property (nonatomic, strong, readwrite) UIImageView *commentImageView;
@property (nonatomic, strong, readwrite) UILabel *commentLabel;

@property (nonatomic, strong, readwrite) UIImageView *likeImageView;
@property (nonatomic, strong, readwrite) UILabel *likeLabel;

@property (nonatomic, strong, readwrite) UIImageView *shareImageView;
@property (nonatomic, strong, readwrite) UILabel *shareLabel;
@end

@implementation GTVideoToolBar

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];

    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self addSubview:({
            self.avatorImageView = [[UIImageView alloc]initWithFrame:CGRectZero];
            self.avatorImageView.layer.masksToBounds = YES;
            self.avatorImageView.layer.cornerRadius = 15;
            self.avatorImageView.translatesAutoresizingMaskIntoConstraints = NO;
            self.avatorImageView;
        })];
        [self addSubview:({
            self.nickLabel = [[UILabel alloc]init];
            self.nickLabel.font = [UIFont systemFontOfSize:15];
            self.nickLabel.textColor = [UIColor lightGrayColor];
            self.nickLabel.translatesAutoresizingMaskIntoConstraints = NO;
            self.nickLabel;
        })];

        [self addSubview:({
            self.commentImageView = [[UIImageView alloc]initWithFrame:CGRectZero];
            self.commentImageView.layer.masksToBounds = YES;
            self.commentImageView.layer.cornerRadius = 15;
			self.commentImageView.translatesAutoresizingMaskIntoConstraints = NO;
            self.commentImageView;
        })];
        [self addSubview:({
            self.commentLabel = [[UILabel alloc]init];
            self.commentLabel.font = [UIFont systemFontOfSize:15];
            self.commentLabel.textColor = [UIColor lightGrayColor];
            self.commentLabel.translatesAutoresizingMaskIntoConstraints = NO;
            self.commentLabel;
        })];

        [self addSubview:({
            self.likeImageView = [[UIImageView alloc]initWithFrame:CGRectZero];
            self.likeImageView.layer.masksToBounds = YES;
            self.likeImageView.layer.cornerRadius = 15;
			self.likeImageView.translatesAutoresizingMaskIntoConstraints = NO;
            self.likeImageView;
        })];
        [self addSubview:({
            self.likeLabel = [[UILabel alloc]init];
            self.likeLabel.font = [UIFont systemFontOfSize:15];
            self.likeLabel.textColor = [UIColor lightGrayColor];
            self.likeLabel.translatesAutoresizingMaskIntoConstraints = NO;
            self.likeLabel;
        })];


        [self addSubview:({
            self.shareImageView = [[UIImageView alloc]initWithFrame:CGRectZero];
            self.shareImageView.layer.masksToBounds = YES;
            self.shareImageView.layer.cornerRadius = 15;
			self.shareImageView.translatesAutoresizingMaskIntoConstraints = NO;
            self.shareImageView;
        })];
        [self addSubview:({
            self.shareLabel = [[UILabel alloc]init];
            self.shareLabel.font = [UIFont systemFontOfSize:15];
            self.shareLabel.textColor = [UIColor lightGrayColor];
            self.shareLabel.translatesAutoresizingMaskIntoConstraints = NO;
            self.shareLabel;
        })];
    }

    return self;
}

- (void)layoutWithModel:(id)model {
//    self.backgroundColor = [UIColor redColor];

    self.avatorImageView.image = [UIImage imageNamed:@"icon"];
    self.nickLabel.text = @"极客时间";

	self.commentImageView.image = [UIImage imageNamed:@"comment"];
	self.commentLabel.text=@"100";

	self.likeImageView.image = [UIImage imageNamed:@"praise"];
	self.likeLabel.text=@"25";

	self.shareImageView.image = [UIImage imageNamed:@"share"];
	self.shareLabel.text=@"分享";

	[self.avatorImageView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerY.equalTo(self.mas_centerY);
		make.width.height.equalTo([NSNumber numberWithInt:30]);
	}];
	
	[self.nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerY.equalTo(self.avatorImageView.mas_centerY);
		make.left.mas_equalTo(self.avatorImageView.mas_right);
	}];
	
	
	
	[self.shareLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerY.equalTo(self.avatorImageView.mas_centerY);
		make.right.mas_equalTo(self.mas_right).with.offset(-15);
	}];
	
	[self.shareImageView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerY.equalTo(self.mas_centerY);
		make.width.height.equalTo([NSNumber numberWithInt:30]);
		make.right.mas_equalTo(self.shareLabel.mas_left);
	}];
	
	[self.likeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerY.equalTo(self.avatorImageView.mas_centerY);
		make.right.mas_equalTo(self.shareImageView.mas_left).with.offset(-15);
	}];
	
	[self.likeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerY.equalTo(self.mas_centerY);
		make.width.height.equalTo([NSNumber numberWithInt:30]);
		make.right.mas_equalTo(self.likeLabel.mas_left);
	}];
	
	[self.commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerY.equalTo(self.avatorImageView.mas_centerY);
		make.right.mas_equalTo(self.likeImageView.mas_left).with.offset(-15);
	}];
	
	[self.commentImageView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerY.equalTo(self.mas_centerY);
		make.width.height.equalTo([NSNumber numberWithInt:30]);
		make.right.mas_equalTo(self.commentLabel.mas_left);
	}];
	

	
	
//    [NSLayoutConstraint
//	 activateConstraints:@[
//         [NSLayoutConstraint constraintWithItem:self.avatorImageView
//                                      attribute:NSLayoutAttributeCenterY
//                                      relatedBy:NSLayoutRelationEqual
//                                         toItem:self
//                                      attribute:NSLayoutAttributeCenterY
//                                     multiplier:1
//                                       constant:0],
//
//         [NSLayoutConstraint constraintWithItem:self.avatorImageView
//                                      attribute:NSLayoutAttributeLeft
//                                      relatedBy:NSLayoutRelationEqual
//                                         toItem:self
//                                      attribute:NSLayoutAttributeLeft
//                                     multiplier:1
//                                       constant:15],
//
//         [NSLayoutConstraint constraintWithItem:self.avatorImageView
//                                      attribute:NSLayoutAttributeWidth
//                                      relatedBy:NSLayoutRelationEqual
//                                         toItem:nil
//                                      attribute:NSLayoutAttributeNotAnAttribute
//                                     multiplier:1
//                                       constant:30],
//
//         [NSLayoutConstraint constraintWithItem:self.avatorImageView
//                                      attribute:NSLayoutAttributeHeight
//                                      relatedBy:NSLayoutRelationEqual
//                                         toItem:nil
//									  attribute:NSLayoutAttributeNotAnAttribute
//                                     multiplier:1
//                                       constant:30],
//
//         [NSLayoutConstraint constraintWithItem:self.nickLabel
//								   attribute:NSLayoutAttributeCenterY
//								   relatedBy:NSLayoutRelationEqual
//									  toItem:self.avatorImageView
//								   attribute:NSLayoutAttributeCenterY
//								  multiplier:1
//									constant:0],
//
//         [NSLayoutConstraint constraintWithItem:self.nickLabel
//                                      attribute:NSLayoutAttributeLeft
//                                      relatedBy:NSLayoutRelationEqual
//                                         toItem:self.avatorImageView
//                                      attribute:NSLayoutAttributeRight
//                                     multiplier:1
//                                       constant:0],
//
//    ]];
	
//	NSString *vflString =@"H:|-15-[_avatorImageView]-0-[_nickLabel]-(>=0)-[_commentImageView(==_avatorImageView)]-0-[_commentLabel]-15-[_likeImageView(==_avatorImageView)]-0-[_likeLabel]-15-[_shareImageView(==_avatorImageView)]-0-[_shareLabel]-15-|";
//	[NSLayoutConstraint activateConstraints:
//		 [NSLayoutConstraint
//		   constraintsWithVisualFormat:vflString
//		   options:NSLayoutFormatAlignAllCenterY
//		   metrics:nil
//		   views:NSDictionaryOfVariableBindings(_avatorImageView, _nickLabel, _commentImageView, _commentLabel,_likeImageView,_likeLabel, _shareImageView, _shareLabel)
//		  ]];
}

@end
